/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package personal.recommender.demo;

import java.util.List;
import personal.recommender.bayesian.PersonalRecommender;
import personal.recommender.objects.User;
import personal.recommender.objects.Video;

/**
 *
 * @author Aya
 */
public class Demo {
    
    public static void main(String[]args){
        
        /* Set the configuration parameters */
        PersonalRecommender.setPath("C:\\Users\\Aya\\RWTH Aachen\\Courses\\Thesis\\Thesis\\Created Networks");
        PersonalRecommender.setKBFile("Knowledge Base");
        PersonalRecommender.setVBFile("Video Base");
        PersonalRecommender.setInterestThreshold(0.6);
        PersonalRecommender.setVideoThreshold(0.5);
        
        /* Build the networks */
        refreshNetworks();
        
        /* Create users */
        //createUserInterestedIn(3, "Health");
        //System.out.println("--------------------------");
        //createUserInterestedIn(4, "Sports");
        //System.out.println("--------------------------");
        //createUserInterestedIn(3, "Politics");
        
    }
    
    public static void refreshNetworks(){
        /* Build the knowledge base (only once) */
        long start = System.currentTimeMillis();
        PersonalRecommender.buildKB("LUMOPedia Knowledge Base");
        long end = System.currentTimeMillis();
        System.out.println("Built the Knowledge base from the database in "+(end-start)+" ms");
        /* Build the video base (only once) and knowledge base needed in advance */
        start = System.currentTimeMillis();
        PersonalRecommender.buildVB("LTV Video Base");
        end = System.currentTimeMillis();
        System.out.println("Built the video base from the knowledge base in "+(end-start)+" ms");
        
    }
    
    public static void createUserInterestedIn(int n, String topic){
        User u = new User();
        List<Video> videos = PersonalRecommender.getVideosWithTopic(topic);
        
        for(int i=0; i<n; i++){
            int ind = (int)(Math.random()*(videos.size()-1));
            Video v = videos.get(ind);
            u.watch(v);
            System.out.println("Watching video "+v.getTitle()+" about "+v.getTopic());
            videos.remove(v);
        }
        
        /* Get recommendations */
        getInformation(u);
    }
    
    public static void getInformation(User u){
        System.out.println("-------------Inferred Interests-----------");
        long start = System.currentTimeMillis();
        PersonalRecommender.fetchInferredInterests(u, 10);
        long end = System.currentTimeMillis();
        System.out.println("Inferred interests in "+(end-start)+" ms\n\n");
        System.out.println("------------Recommendations----------------");
        start = System.currentTimeMillis();
        PersonalRecommender.fetchRecommendations(u, 3);
        end = System.currentTimeMillis();
        System.out.println("Fetched recommendations in "+(end-start)+" ms\n\n");
    }
}
